export interface Permission {
  pmsType: number;
  keyword: string;
  children?: Permission[];
}

export const getPermissions = (array: Permission[]) => {
  const permissions = [] as string[];

  const helper = (array: Permission[]) => {
    array.forEach(item => {
      if ([1, 4].includes(item.pmsType)) {
        permissions.push(item.keyword);
      }
      if (!typeChecker.isEmpty(item.children)) {
        helper(item.children!);
      }
    });
  };

  helper(array);

  return permissions;
};

export const hasPermission = (permission: string) => {
  const permissions = cache.get('user').permissions;
  return permissions.includes(permission);
};
